package com.smile.service.impl;

import com.smile.model.dto.request.*;
import com.smile.service.LiveService;
import com.smile.service.task.FlyServicesExecutor;
import com.smile.service.task.LiveServicesExecutor;
import org.eclipse.paho.client.mqttv3.MqttException;
import org.springframework.stereotype.Service;

import java.util.Objects;

@Service
public class LiveServiceImpl implements LiveService {
    @Override
    public void liveLensChange(LiveLensChangeRequestDTO liveLensChangeRequestDTO) throws MqttException {
        ///**
        //     * 0红外
        //     * 1默认
        //     * 2广角
        //     * 3变焦
        //     */
        switch (liveLensChangeRequestDTO.getVideoType()) {
            case 0:
                LiveServicesExecutor.create()
                        .sn(liveLensChangeRequestDTO.getSn())
                        .liveLensChange("ir").gateway(liveLensChangeRequestDTO.getGateway()).execute();
                break;
            case 1:
                LiveServicesExecutor.create()
                        .sn(liveLensChangeRequestDTO.getSn())
                        .liveLensChange("normal").gateway(liveLensChangeRequestDTO.getGateway()).execute();
                break;
            case 2:
                LiveServicesExecutor.create()
                        .sn(liveLensChangeRequestDTO.getSn())
                        .liveLensChange("wide").gateway(liveLensChangeRequestDTO.getGateway()).execute();
                break;
            case 3:
                LiveServicesExecutor.create()
                        .sn(liveLensChangeRequestDTO.getSn())
                        .liveLensChange("zoom").gateway(liveLensChangeRequestDTO.getGateway()).execute();
                break;
        }
    }

    @Override
    public void liveCameraChange(LiveCameraChangeRequestDTO liveCameraChangeRequestDTO) throws MqttException {
        LiveServicesExecutor.create()
                .sn(liveCameraChangeRequestDTO.getSn())
                .liveCameraChange(liveCameraChangeRequestDTO.getCameraPosition())
                .gateway(liveCameraChangeRequestDTO.getGateway()).execute();
    }

    @Override
    public void liveSetQuality(LiveSetQualityRequestDTO liveSetQualityRequestDTO) throws MqttException {
        LiveServicesExecutor.create()
                .sn(liveSetQualityRequestDTO.getSn())
                .liveSetQuality(liveSetQualityRequestDTO.getVideoQuality())
                .gateway(liveSetQualityRequestDTO.getGateway()).execute();
    }

    @Override
    public void liveStartPush(LiveStartPushRequestDTO liveStartPushRequestDTO) throws MqttException {
        String sn = liveStartPushRequestDTO.getSn();
        if (sn == null) {
            sn = liveStartPushRequestDTO.getGateway();
        }
        if (Objects.isNull(liveStartPushRequestDTO.getType())){

            LiveServicesExecutor
                    .create()
                    .sn(sn)
                    .liveStartPush(liveStartPushRequestDTO.getUrl())
                    .gateway(liveStartPushRequestDTO.getGateway())
                    .execute();
        }else{
            LiveServicesExecutor
                    .create()
                    .sn(sn,liveStartPushRequestDTO.getType())
                    .liveStartPush(liveStartPushRequestDTO.getUrl())
                    .gateway(liveStartPushRequestDTO.getGateway())
                    .execute();
        }
    }

    @Override
    public void liveStopPush(LiveStopPushRequestDTO liveStopPushRequestDTO) throws MqttException {
        LiveServicesExecutor
                .create()
                .sn(liveStopPushRequestDTO.getSn())
                .liveStopPush()
                .gateway(liveStopPushRequestDTO.getGateway())
                .execute();
    }
}
